package com.client;

import com.utils.LogUtil;

import java.security.PrivateKey;


/**
 * 使用{@code Key(PrivateKey,PublicKey)} 来初始化RepChainClient
 * @author zyf
 */
public class RepChainKeyClient extends RepChainClient {

    public RepChainKeyClient() {
    }

    /**
     * @param host 服务主机地址
     */
    public RepChainKeyClient(String host) {
        super(host);
    }

    /**
     * 使用私钥初始化
     * @param host RepChain服务地址
     * @param privateKey  用来初始化的私钥
     */
    public RepChainKeyClient(String host, PrivateKey privateKey) {
        try {
            this.host = host;
            initialKey(privateKey);
        } catch (Exception e) {
            e.printStackTrace();
            logMsg(LogUtil.LogType.Error, e.getMessage());
        }
    }

    /**
     * 设置私钥
     * @param privateKey
     */
    public void setPrivateKey(PrivateKey privateKey) {
        initialKey(privateKey);
    }

    /**
     * 初始化keyClient客户端
     * @param privateKey
     */
    private void initialKey(PrivateKey privateKey) {
        this.privateKey = privateKey;
        this.keyInit = true;
        logMsg(LogType.Info,"RepChainClient使用Key初始化成功");
    }
}
